<template>
	<view>
		<uni-forms ref="form" :modelValue="formData" :rules="rules">
			<uni-forms-item label="用户名" name="username">
				<uni-easyinput type="text" v-model="formData.username" placeholder="请输入用户名" />
			</uni-forms-item>
			<uni-forms-item label="密码" name="password">
				<input class="input" v-model="formData.password" type="password" 
				placeholder="请输入密码" />
			</uni-forms-item>
		</uni-forms>
		<button @click="submitLogin">登录</button>
	</view>
</template>

<script setup>
	import { onMounted, ref } from "vue";
	// 在页面中导入相关 api 
	import {
		login,
	} from "@/api/order.js";

	// 定义存储请求的结果
	// const order = ref([]);

	// 也买你加载完毕执行
	onMounted(() => {
		// 调用函数
		login();
	})
	const formData = ref({
		"username":"",
		"password":""
	})
	
	const submitLogin = async () =>{
		let res = await login(formData.value)
		uni.setStorageSync("token",res.data)
		if(res.code==200){
			uni.switchTab({
				url:"/pages/index/index"
			})
		}
		console.log(res);
	}
	
	// 封装函数，调用 api
	const getOrder = async () => {
		let res = await login(1);
		console.log(res);
	}
</script>

<style>

</style>